home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_dev-disk / egsdemos / egsexamples / stack_language / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  3.1 KB  |  181 lines

  1. /*
  2. *  $
  3. *  $ FILE     : main.c
  4. *  $ VERSION  : 1
  5. *  $ REVISION : 12
  6. *  $ DATE     : 08-Dec-93 19:34
  7. *  $
  8. *  $ Author   : mvk
  9. *  $
  10. *
  11. **  This demo shows you the possibility to make Gadgets
  12. **  with the EGS STACK-LANGUAGE. But remmber the egsgadbox.lib
  13. **  normaly you didn't need the STACK-LANGUAGE, because you can
  14. **  do the same stuff much easier with the egsgadbox.library
  15. **  (refer demo gadget).
  16. **
  17. **
  18. **  In this Files you will find some usefull routines
  19. **  for Open / Close Libraries and ErrorHandling
  20. **
  21. **  (c) by VIONA-Development
  22. **
  23. */
  24.  
  25. #include "includes.c"
  26. #include "Global.h"
  27. #include "stack-language.c"
  28. #include "Eventloop.c"
  29. #include "InitMenu.c"
  30.  
  31. BOOL InitLibraries(struct OpenStructTyp *);
  32. void CloseLibraries(struct OpenStructTyp *);
  33.  
  34.  
  35. /*
  36. **  Opens the libs form the OpenStructTyp
  37. **  (see global.h)
  38. **
  39. */
  40.  
  41. BOOL InitLibraries(struct OpenStructTyp *OS)
  42. {
  43.  struct OpenStructTyp *p = &OS[0];
  44.  
  45.  while (p->Ort != NULL)
  46.  {
  47.    if ((*(p->Ort) = (ULONG)OpenLibrary(p->Name,p->Version)) == NULL)
  48.        {
  49.        printf(" Can't open %s version %d",p->Name, p->Version);
  50.        return FALSE;
  51.        }
  52.        else
  53.        {  p ++; }
  54.  }
  55.    return TRUE;
  56. }
  57.  
  58.  
  59. /*
  60. ** Close the Libs from the OpenStructTyp
  61. **
  62. */
  63. void CloseLibraries(struct OpenStructTyp *OS)
  64. {
  65.  struct OpenStructTyp *p = &OS[0];
  66.  
  67.  while (p->Name != NULL)
  68.  {
  69.     CloseLibrary((void *)(*(p->Ort)));
  70.     *(p->Ort) = NULL;
  71.     p++;
  72.  }
  73. }
  74. /**/
  75.  
  76.  
  77. /*
  78. ** This routine is for Errorhandling.
  79. ** It close all open thinks form the
  80. ** program.
  81. **
  82. */
  83. void myError(char *string)
  84. {
  85.   if ( string != NULL)
  86.   {
  87.       if ( EGSRequestBase == NULL )
  88.       {
  89.       printf("%s\n",string);
  90.  
  91.       }else{
  92.  
  93.      ErrorReq = ER_CreateSimpleReq(NULL,(char *)string,(char *)"OK");
  94.  
  95.      /*
  96.      **  Open Requester in the middle of the Screen,
  97.      **
  98.      **  if you could !?
  99.      */
  100.  
  101.      ErrorReq->Req.Nw->Flags |= EI_WINDOWCENTER;
  102.  
  103.      ER_DoRequest(&(ErrorReq->Req)) ;
  104.       }
  105.   }
  106.  
  107.   if (Window)
  108.   {
  109.  
  110.   ErrorReq = ER_CreateSimpleReq(NULL,
  111.         "Hello world !|This is a Requester !","OK");
  112.  
  113.   ErrorReq->Req.Nw->Flags |= EI_WINDOWCENTER;
  114.  
  115.   ER_DoRequest(&(ErrorReq->Req)) ;
  116.   }
  117.  
  118.   if ( FontforMenu )
  119.     EG_CloseFont(FontforMenu);
  120.  
  121.   if ( Window )
  122.     EI_CloseWindow(Window);
  123.  
  124.   if ( Menu )
  125.     EI_FreeMenu(Menu);
  126.  
  127.  if ( ErrorReq )
  128.      ER_DeleteRequest(&(ErrorReq->Req));
  129.  
  130.   CloseLibraries(OpenStruct);
  131.  
  132.  exit(0);
  133.  
  134.  
  135. }
  136. /**/
  137.  
  138. int main(int argc, char *argv[])
  139. {
  140.  
  141.   if (argc == 2 && strcmp("?",argv[1]) == 0)
  142.    {
  143.     printf("Aufruf: %s\n  Markus van Kempen 12 Nov 1992",argv[0]);
  144.  
  145.    }else
  146.    {
  147.  
  148.       if ( InitLibraries(OpenStruct) == FALSE)
  149.       myError("Can't OpenLibrary");
  150.  
  151.       FontforMenu = (EG_EFontPtr)EG_OpenFont((struct TextAttr *)&FontStr);
  152.  
  153.       if ( FontforMenu == NULL )
  154.       myError("Could not open font");
  155.  
  156.     Menu=InitMenu(FontforMenu);
  157.  
  158.       if ( Menu == NULL )
  159.       myError("Could not build Menu");
  160.  
  161.       newwin.FirstGadgets=(struct EI_Gadget *)&myBoolGadget;
  162.       newwin.Menu=Menu;
  163.       newwin.Title=argv[0];
  164.  
  165.       Window = (EI_WindowPtr)EI_OpenWindow ((struct EI_NewWindow *)&newwin);
  166.  
  167.      if (Window)
  168.        {
  169.  
  170.     HandleEvents(Window);
  171.  
  172.     }else{
  173.            myError("Could not open window");
  174.        }
  175.    }
  176.   myError(NULL);
  177. }
  178.  
  179.  
  180.  
  181.